package com.evil.enterprise.controller;

import com.evil.application.api.RemoteApplicationPrintTemplateService;
import com.evil.application.pojo.dto.template.*;
import com.evil.application.pojo.dto.template.print.*;
import com.evil.common.core.entity.R;
import com.evil.common.file.constant.OssConstant;
import com.evil.common.file.dto.FileRespDTO;
import com.evil.common.file.enums.BusTypeEnum;
import com.evil.common.log.annotation.RequestLogAnnotation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 应用打印模板接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/application/print-template")
public class ApplicationPrintTemplateController {

    private final RemoteApplicationPrintTemplateService remoteApplicationPrintTemplateService;

    /**
     * 打印模板列表接口
     *
     * @param printTemplateListReqDTO templateListReqDTO
     * @return R
     */
    @PostMapping("/list")
    public R<?> list(@Validated @RequestBody PrintTemplateListReqDTO printTemplateListReqDTO) {
        printTemplateListReqDTO.setEnterpriseId(null);
        return R.success(remoteApplicationPrintTemplateService.list(printTemplateListReqDTO));
    }

    /**
     * 保存打印模板文件
     *
     * @param savePrintTemplateReqDTO addUploadTemplateReqDTO
     * @return R
     */
    @RequestLogAnnotation(isSaveRequestData = false)
    @PostMapping("/save")
    public R<?> save(@Validated @RequestBody SavePrintTemplateReqDTO savePrintTemplateReqDTO) {
        remoteApplicationPrintTemplateService.save(savePrintTemplateReqDTO);
        return R.success();
    }

    /**
     * 重命名打印模板
     *
     * @param renamePrintTemplateReqDTO templateRenameReqDTO
     * @return R
     */
    @PostMapping("/rename")
    public R<?> rename(@Validated @RequestBody RenamePrintTemplateReqDTO renamePrintTemplateReqDTO) {
        remoteApplicationPrintTemplateService.rename(renamePrintTemplateReqDTO);
        return R.success();
    }

    /**
     * 删除打印模板
     *
     * @param deletePrintTemplateReqDTO deleteTemplateReqDTO
     * @return R
     */
    @RequestLogAnnotation
    @PostMapping("/delete")
    public R<?> delete(@Validated @RequestBody DeletePrintTemplateReqDTO deletePrintTemplateReqDTO) {
        remoteApplicationPrintTemplateService.delete(deletePrintTemplateReqDTO);
        return R.success();
    }

    /**
     * 打印模板详情
     *
     * @param printTemplateDetailReqDTO templateDetailReqDTO
     * @return R
     */
    @PostMapping("/detail")
    public R<?> detail(@Validated @RequestBody PrintTemplateDetailReqDTO printTemplateDetailReqDTO) {
        return R.success(remoteApplicationPrintTemplateService.detail(printTemplateDetailReqDTO));
    }

    /**
     * 上传打印模板
     *
     * @param uploadTemplateReqDTO uploadTemplateReqDTO
     * @return R
     */
    @PostMapping("/template")
    public R<FileRespDTO> upload(@Validated UploadTemplateReqDTO uploadTemplateReqDTO) {
        uploadTemplateReqDTO.setType(BusTypeEnum.APPLICATION_PRINT_TEMPLATE_FILE.getId());
        uploadTemplateReqDTO.setAllowContentType(OssConstant.UPLOAD_WORD_TYPE);
        uploadTemplateReqDTO.setAllowMaxSize(OssConstant.UPLOAD_FILE_SIZE);
        return R.success(remoteApplicationPrintTemplateService.upload(uploadTemplateReqDTO));
    }

    /**
     * 下载打印模板文件接口
     *
     * @param downloadPrintTemplateReqDTO downloadTemplateReqDTO
     * @return R
     */
    @PostMapping("/download")
    public R<?> download(@Validated @RequestBody DownloadPrintTemplateReqDTO downloadPrintTemplateReqDTO) {
        return R.success(remoteApplicationPrintTemplateService.download(downloadPrintTemplateReqDTO));
    }

    /**
     * 打印模板数据
     *
     * @param printTemplateReqDTO printTemplateReqDTO
     */
    @PostMapping("/print")
    public R<FileRespDTO> printTemplate(@Validated @RequestBody PrintTemplateReqDTO printTemplateReqDTO) {
        return R.success(remoteApplicationPrintTemplateService.printTemplate(printTemplateReqDTO));
    }
}
